home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD-Sensation: Golden Games / Amiga CD-Sensation - Ausgabe 2 - Golden Games (1996)(GTI - Schatztruhe)(DE)[!].iso / Various / CRobots / CRobots.doc < prev    next >
Text File  |  1990-04-16  |  61KB  |  1,622 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.      _____________________________________________________________
  13.     |                                                             |
  14.     |:                                                           :|
  15.     |    #####  ######  ####### ######  ####### #######  #####    |
  16.     |   #     # #     # #     # #     # #     #    #    #     #   |
  17.     |   #       #     # #     # #     # #     #    #    #         |
  18.     |   #       ######  #     # ######  #     #    #     #####    |
  19.     |   #       #   #   #     # #     # #     #    #          #   |
  20.     |   #     # #    #  #     # #     # #     #    #    #     #   |
  21.     |    #####  #     # ####### ######  #######    #     #####    |
  22.     |:                                                           :|
  23.     |_____________________________________________________________|
  24.  
  25.  
  26.                   ___                   ____      ___
  27.                  /   \    /\ /\    *   /    \    /   \
  28.                 /     \  /  V  \   _  |         /     \
  29.                 |     |  |     |  | | |     _   |     |
  30.                 |-----|  |     |  | | |      \  |-----|
  31.                 |     |  | |V| |  | | |       | |     |
  32.                 |     |  |_| |_|  |_|  \_____/  |     |
  33.  
  34.  
  35.  
  36.         (C) Copyright 1985, Tom Poindexter
  37.         (C) Copyright 1989-90, David Wright - Amiga Version
  38.  
  39.  
  40.            David Wright
  41.            4262 Bennington
  42.            Brunswick, OH 44212
  43.            USA
  44.            (216) 273-1064
  45.            davewt@NCoast.ORG
  46.            uunet!hal!ncoast!davewt
  47.            uunet!cwjcc!ncoast!davewt  (prefered)
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. Tom Poindexter '85                                      David Wright '89-90
  64.  
  65.  
  66.                            _1_.  _D_i_s_t_r_i_b_u_t_i_o_n _a_g_r_e_e_m_e_n_t_:
  67.  
  68.           You may  make copies of this program, manual, and other files and
  69.        give  them to your friends, upload it to bulletin boards, or include
  70.        it  in  the library of a non-profit computer club. In short, you are
  71.        free  to  distribute  at will with the exception of distribution for
  72.        profit.  
  73.  
  74.                                  _2_.  _I_n_t_r_o_d_u_c_t_i_o_n
  75.  
  76.        _2_-_1_.  _D_e_s_c_r_i_p_t_i_o_n 
  77.  
  78.           CRobots ("see-robots")  is  a game based on computer programming.
  79.        Unlike  arcade type games which require human input controlling some
  80.        object,  all  strategy in CRobots must be complete before the actual
  81.        game  begins.  Game  strategy is condensed into a C language program
  82.        that  you  design  and  write.  Your  program controls a robot whose
  83.        mission  is  to  seek  out,  track,  and  destroy other robots, each
  84.        running  different  programs. Each robot is equally equipped, and up
  85.        to  four  robots  may  compete at once. CRobots is best played among
  86.        several   people,  each  refining  their  own  robot  program,  then
  87.        matching program against program.  
  88.  
  89.           CRobots consists  of  a  C  compiler,  a  virtual  computer,  and
  90.        battlefield  display.  The  CRobots compiler accecpts a limited (but
  91.        useful)  subset  of  the C language. The robot programs are aided by
  92.        hardware  functions  to  scan  for  opponents,  start and stop drive
  93.        mechanisms,  fire  cannons, etc. After the programs are compiled and
  94.        loaded  into separate robots, the battle is observed. Robots moving,
  95.        missiles  flying  and  exploding, and certain status information are
  96.        displayed on the screen, in real-time.  
  97.  
  98.  
  99.        _2_-_2_.  _I_n_t_e_n_d_e_d _a_u_d_i_e_n_c_e 
  100.  
  101.           CRobots will  most likely appeal to programmers (especially those
  102.        who  think  they  can  write  the  "best"  programs),  computer game
  103.        enthusiasts,  people  wishing to learn the C language, and those who
  104.        are   interested   in   compiler   design   and   virtual   computer
  105.        interpreters.  
  106.  
  107.  
  108.        _2_-_3_.  _M_a_c_h_i_n_e _a_n_d _s_o_f_t_w_a_r_e _r_e_q_u_i_r_e_m_e_n_t_s 
  109.  
  110.                - Amiga 500, 1000, 2000, 2500
  111.                - 512k of RAM
  112.                - DOS 1.3 or higher
  113.                - ARP 1.3 or higher
  114.                - Monochrome or Color monitor
  115.                - Text editor (UE, TxEd, or your own favorite)
  116.  
  117.  
  118.  
  119.  
  120.                                   Page 1
  121.  
  122.  
  123. Tom Poindexter '85                                      David Wright '89-90
  124.  
  125.  
  126.           NOTE FOR  512K  1000  & 500 USERS: I have tested version 2.3 on a
  127.        512k  1000,  and  was  able to get it to work. If you have problems,
  128.        try  setting  the  stack  size to 25 or 30k. I was able to get it to
  129.        run  by  breaking  out of the startup-sequence, setting the stack to
  130.        30k,  and  then  running  it. It might work with WB loaded, but with
  131.        only  512k  it  might  be  tight,  and  you might need to remove any
  132.        external drives.  
  133.  
  134.        _2_-_4_.  _U_s_e_r _i_n_t_e_r_f_a_c_e 
  135.  
  136.           At the  present time CRobots does not use menus, windows, pop-ups
  137.        (other   than   a   file  requester),  or  any  other  user-friendly
  138.        interface.   Since  the  emphasis  is on designing and writing robot
  139.        control  programs, CRobots is usually started as a compiler is, from
  140.        the  AmigaDOS  command  line,  although  a  WorkBench  interface  is
  141.        available.  
  142.  
  143.  
  144.                                  _3_. _T_y_p_e_s _o_f _p_l_a_y
  145.  
  146.           CRobots can  either  run  one  match  (single play), in which the
  147.        realtime  battlefield  simulator  is used, or several matches (match
  148.        play),  in  which  only the name of the winner is printed after each
  149.        match.  Single  play  is  the default. Match play is intended to see
  150.        how  robot  programs  perform on the average. Match play can consume
  151.        several  hours  of  computer time depending on the number of matches
  152.        and cpu cycle limit, and can be run overnight.  
  153.  
  154.  
  155.                                _4_.  _R_u_n_n_i_n_g _C_R_o_b_o_t_s
  156.  
  157.        _4_-_1_.  _C_o_m_m_a_n_d _l_i_n_e _o_p_t_i_o_n_s 
  158.  
  159.           CRobots can  be  started  from the CLI or a WorkBench icon. If it
  160.        is started from the CLI you may also specify several options.  
  161.  
  162.        Sample command line: 
  163.  
  164.          1>crobots [options] [robot-program-1 ... robot-program-n]
  165.  
  166.        Valid options are:
  167.  
  168.        TO file         Save the output from the compile listing ("COMPILE"
  169.                        option) or record matches ("MATCH" option) to <file>.
  170.  
  171.        COMPILE         Compile only, and produce virtual machine assembler
  172.                        code and symbol tables. You must have the source code
  173.                        (.r file) for a robot to use this function.
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.                                   Page 2
  181.  
  182.  
  183. Tom Poindexter '85                                      David Wright '89-90
  184.  
  185.  
  186.        DEBUG           Compile one program, and invoke machine level
  187.                        single step tracing. You must have the source code
  188.                        (.r file) for a robot to use this function.
  189.  
  190.        MATCH xxx       Run a series of matches, where "xxx" is the number
  191.                        of matches. If "MATCH" is NOT specified, then the
  192.                        default is to run one match and display the
  193.                        battlefield in realtime. If the MATCH option IS
  194.                        selected, all the robots must be pre-compiled.
  195.  
  196.        LIMIT xxx       Limit the number of machine cpu cycles per match
  197.                        when "MATCH" is specified. The default cycle limit
  198.                        is 500,000.
  199.  
  200.        NOSHOW          Turn off compilation display to increase speed.
  201.  
  202.        NOWAIT          Turn off the "press any key" messages. Used mainly
  203.                        when running a series of matches and output is
  204.                        directed to a file with the TO option.
  205.  
  206.        robot-programs  The file name of the CRobots source program(s).
  207.                        (Wildcards allowed) Up to four files may be
  208.                        specified. If only one file is specified, it will
  209.                        be "cloned" into another, so that two robots
  210.                        (running the same program) will compete. Any file
  211.                        name may be used, but for consistency please use
  212.                        '.r' as an extension for source code. If you do
  213.                        not give any robot file names, all the names you
  214.                        give can't be found, or you run CRobots from the
  215.                        WorkBench, the ARP file requester will come up
  216.                        and allow you to select up to 4 robots.
  217.                        If you do not wish to load 4 robots, just click
  218.                        the CANCEL gadget after selecting the last robot
  219.                        you want to load.
  220.  
  221.           Note that  some of these options are mutually-exclusive, and that
  222.        others will have no effect depending on the mode you are in.  
  223.  
  224.        _4_-_2_.  _E_x_a_m_p_l_e_s_:
  225.  
  226.                1) Watch three robots compete with full display:
  227.                     1>crobots robot1.cr robot2.cr robot3.cr
  228.  
  229.                2) Compile one robot, and save the listing:
  230.                     1>crobots COMPILE TO robot1.lst robot1.r
  231.  
  232.                3) Debug a robot (first get an assembler code listing,
  233.                   as in example 2:
  234.                     1>crobots DEBUG robot1.r
  235.  
  236.                4) Run 50 matches, limiting total cpu cycles to 200,000
  237.                   (per match), and save results:
  238.  
  239.  
  240.                                   Page 3
  241.  
  242.  
  243. Tom Poindexter '85                                      David Wright '89-90
  244.  
  245.  
  246.                     1>crobots MATCH 50 LIMIT 200000 TO save rbt1.cr rbt2.cr
  247.  
  248.                5) Display command line options
  249.                     1>crobots ?<return>?<return>
  250.  
  251.  
  252.        _4_-_3_. _R_u_n_n_i_n_g _C_R_o_b_o_t_s _f_r_o_m _t_h_e _W_o_r_k_B_e_n_c_h 
  253.  
  254.           If you  wish you may start CRobots from the WorkBench by clicking
  255.        on  it's  icon.  You  may also specify some of the options that were
  256.        available  from  the CLI by using the icon's "tool types" array. You
  257.        can  edit  this  array by clicking on the CRobots icon _o_n_c_e and then
  258.        selecting  the  menu  option  "Info". You will see a blank line that
  259.        has  ADD  and  DEL  gadgets to the right of it. Click the ADD gadget
  260.        and  a  cursor  will  appear at the start of the blank line. Type in
  261.        one  of  the  following keywords followed by an equals sign, and the
  262.        value  you  want  (value  limits are the same as for the CLI options
  263.        above): 
  264.  
  265.                   MATCHES 
  266.                   LIMIT 
  267.                   NOSHOW 
  268.  
  269.           Matches and  limit  take  numeric  arguments,  as  under the CLI,
  270.        while  the  noshow option should be followed by a YES if you wish to
  271.        turn the option on (see above for what the noshow flag does).  
  272.           You may  add  as  many of these options as you wish, but you must
  273.        use  the ADD gadget to create each new option, and the DEL gadget to
  274.        delete options that you no longer want.  
  275.           Once you  have added/deleted the options that you want, click the
  276.        SAVE gadget to exit and save them to disk.  
  277.  
  278.        _4_-_4_. _W_o_r_k_b_e_n_c_h _e_x_a_m_p_l_e_s 
  279.  
  280.                   1) Set the number of matches to 3, with a limit of 
  281.                      20,000 cycles per match: 
  282.                           MATCHES=3 
  283.                           LIMIT=20000 
  284.  
  285.                   2) Turn off screen output of robot compilations: 
  286.                           NOSHOW=YES 
  287.  
  288.  
  289.                                _5_.  _G_a_m_e _p_a_r_a_m_e_t_e_r_s
  290.  
  291.        _5_-_1_.  _B_a_t_t_l_e_f_i_e_l_d 
  292.  
  293.           The battlefield  is  a  1,000  by  1,000  meter  square.  A  wall
  294.        surrounds  the perimeter, so that a robot running into the wall will
  295.        incur  damage. Note that as screen resolution is obviously less than
  296.        1000x1000,  there  is  bound  to be some error is scaling which will
  297.        make  robots  appear  to  be hit by pulses when they take no damage.
  298.  
  299.  
  300.                                   Page 4
  301.  
  302.  
  303. Tom Poindexter '85                                      David Wright '89-90
  304.  
  305.  
  306.        Robots  may  also appear to go over each other, and take damage from
  307.        hitting  walls  when  they  appear to be a slight distance away from
  308.        them.  
  309.  
  310.           The lower  left  corner  has  the  coordinates  x = 0, y = 0; the
  311.        upper  right  corner has the coordinates x = 999, y = 999. There are
  312.        grids  on  the  floor of the battlefield, and emitter/detector pairs
  313.        on  the  bottom  of  the  robot which allow it to keep track of it's
  314.        position much like an optical mouse.  
  315.  
  316.           The compass  system  is  oriented  so  that due east (right) is 0
  317.        degrees,  90  is  north, 180 is west, 270 is south. One degree below
  318.        due east is 359.  
  319.  
  320.  
  321.                         135    90   45
  322.                             \  |  / 
  323.                              \ | /
  324.                        180 --- x --- 0
  325.                              / | \
  326.                             /  |  \ 
  327.                         225   270   315
  328.  
  329.  
  330.        _5_-_2_.  _R_o_b_o_t _o_f_f_e_n_s_e
  331.  
  332.           The main  offensive  weapons are the phased particle cannon (PPC)
  333.        and  scanner.  The  PPC  has  a  range of 700 meters. The PPC may be
  334.        fired  an  unlimited  number  of  times,  but  a  recharging  factor
  335.        effectively  limits  the number of pulses in the air at any one time
  336.        to  two.  The PPC is mounted on an independent turret, and therefore
  337.        can fire any direction, 0-359, regardless of robot heading.  
  338.  
  339.           The scanner  is  an  optical  device  that can instantly scan any
  340.        chosen  heading,  0-359. The scanner has a maximum resolution of +/-
  341.        10  degrees.   This enables the robot to quickly scan the field at a
  342.        low   resolution,   then  use  maximum  resolution  to  pinpoint  an
  343.        opponent.  
  344.  
  345.  
  346.        _5_-_3_.  _R_o_b_o_t _d_e_f_e_n_s_e 
  347.  
  348.           The only  defenses  available  are  the  motor  drive  and status
  349.        registers.  The  motor  can  be  engaged  on  any heading, 0-359, in
  350.        speeds  from  0-100 percent of power. Robot mass is considerable, so
  351.        there  are acceleration and deacceleration delay factors. A speed of
  352.        0  stops  the  motor.  Turns  can be negotiated at speeds of 50% and
  353.        less,  in  any  direction. Of course, the motor drive can be engaged
  354.        any  time,  and  is necessary on offense when a target is beyond the
  355.        700 meter range of the PPC.  
  356.  
  357.           There are   several  embedded  controllers  in  the  robot  which
  358.  
  359.  
  360.                                   Page 5
  361.  
  362.  
  363. Tom Poindexter '85                                      David Wright '89-90
  364.  
  365.  
  366.        utilize  a  shared memory system (18 DMA channels) to update certain
  367.        status  registers  without  tying  up  the  primary  robot  CPU. The
  368.        primary  registers indicate the percent of damage, and current x and
  369.        y  locations  on  the  battlefield.  Another  register  provides the
  370.        current drive speed.  
  371.  
  372.  
  373.        _5_-_4_.  _D_i_s_a_b_l_i_n_g _o_p_p_o_n_e_n_t_s 
  374.  
  375.           A robot  is considered dead when the damage reaches 100%. Percent
  376.        of damage inflicted is as follows: 
  377.  
  378.                2% - collision into another robot (both robots in a
  379.                     collision receive damage) or into a wall. A
  380.                     collision also causes the motor drive to disengage,
  381.                     and speed is reduced to 0.
  382.  
  383.                3% - a pulse impacting within a 40 meter radius.
  384.  
  385.                5% - a pulse impacting within a 20 meter radius.
  386.  
  387.               10% - a pulse impacting within a 5 meter radius.
  388.  
  389.  
  390.           Damage is  cumulative,  and  cannot be repaired. However, a robot
  391.        does  not  lose  any mobility, firing potential, etc. at high damage
  392.        levels.  In other words, a robot at 99% damage performs just as well
  393.        as a robot with no damage.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.                                   Page 6
  421.  
  422.  
  423. Tom Poindexter '85                                      David Wright '89-90
  424.  
  425.  
  426.        _5_-_5_.  _S_a_m_p_l_e _d_i_s_p_l_a_y
  427.  
  428.  
  429.                                                          (Status
  430.                                        (x=999,y=999)        blocks)
  431.  
  432.           +------------------------------------+ 1 fubar.r
  433.           |                                    |  D% 015   Sc 218
  434.           |                          \|/ 1     |  Sp 000   Hd 090
  435.           |       (pulse impacting)  -#-       | ------------------
  436.           |                          /|\       | 2 snafu.r
  437.        (y |                                    |  D% 050   Sc 275
  438.           |              + -------(particle    |  Sp 100   Hd 180
  439.        a  |                     + --pulses)    | ------------------
  440.        x  |   2                                | 3 bimbo.r
  441.        i  |                                    |  D% 000   Sc 045
  442.        s) |                 3                  |  Sp 000   Hd 000
  443.           |                /                   | ------------------
  444.           |          (robots) ----\            | 4 kumquat.r
  445.           |                         4          |  D% 100   Sc 050
  446.           |                                    |  Sp 000   Hd 335
  447.           |                                    | 
  448.           |                                    |
  449.           +------------------------------------+ CPU Cycle: 4500
  450.  
  451.        (x=0,y=0)         (x axis)
  452.  
  453.           The CRobots  battle  console  consists of several color CRT's and
  454.        an  LCD  counter. The largest CRT is the primary battle display, and
  455.        displays  the  battle  in  real-time.  The  smaller CRT's are status
  456.        blocks for each robot.  
  457.  
  458.           Each status  block  shows  the file name of the robot, the damage
  459.        incurred  (D%),  the  current scan degrees (Sc), the speed (Sp), and
  460.        heading  (Hd).  Robots  are  represented  on  the field by a graphic
  461.        item,  which is also displayed to the left of the name in the status
  462.        block  for  reference.  If Damage is below 90%, it will be displayed
  463.        in  green.  If  damage  is between 90 & 100% it will be displayed in
  464.        red. When damage reaches 100%, it will be displayed in black.  
  465.  
  466.           The number  of  elapsed  robot  cpu  cycles  is  shown  in an LCD
  467.        display below the status blocks.  
  468.  
  469.           The CRobots  program  can  be aborted at any time by pressing the
  470.        ESC  key. It may also be paused at almost any time by pressing SPACE
  471.        or CTRL-S, and restarted by pressing SPACE again or CTRL-Q.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.                                   Page 7
  481.  
  482.  
  483. Tom Poindexter '85                                      David Wright '89-90
  484.  
  485.  
  486.        _5_-_6_.  _T_a_b_l_e _o_f _T_i_m_e _C_o_s_t_s 
  487.  
  488.           As just  a  few  CPU  cycles  can  make  the difference between a
  489.        winner  and loser, following is a table of the cost in CPU cycles of
  490.        various actions: 
  491.  
  492.               Action                  Cpu Cycles 
  493.               ---------------------------------- 
  494.               Recharge PPC            150 
  495.               Acc/Decellerate 10%     10 
  496.               Pulse traveling 50 
  497.                   meters              10 
  498.               Robot move 7 meters 
  499.               at 100% speed           1 
  500.  
  501.  
  502.                                  _6_.  _C_R_o_b_o_t_s _C_P_U
  503.  
  504.           The robot  cpu  is  a simple stack-oriented computer. It operates
  505.        at  very  slow  speeds  (on  a  7.8  MHz 68000 Amiga with an average
  506.        amount  of  background tasks running and with two robots loaded, the
  507.        average  speed  is 309 instructions per second, .000309 mips!!). The
  508.        word  size  is  32 bits, allowing integer values from -2,147,483,648
  509.        to  2,147,483,647.  There are internal pointer registers that manage
  510.        stack  usage,  but are not accessible from a robot program. The same
  511.        is true for an implicit accumulator.  
  512.  
  513.            The maximum  code  space is 1,000 instructions. All instructions
  514.        are  equal  in length. The maximum stack size is 500 words, which is
  515.        used  for data and function call/returns. The stack grows upward for
  516.        data  usage,  and downward (from the end) for function call/returns.
  517.        Three  words  are used for each function call, and are released upon
  518.        the  function  return.  The data portion and call/return portion are
  519.        managed by separate internal stack pointers.  
  520.  
  521.           If the  data stack pointer and call/return stack pointer collide,
  522.        a  stack  overflow  occurs.  In this case, the robot is restarted at
  523.        the 'main' function, with the stack reset to all zeros.  
  524.  
  525.           For more  information,  see  the  section on machine instructions
  526.        and theory.  
  527.  
  528.  
  529.                               _7_.  _C_R_o_b_o_t_s _C _c_o_m_p_i_l_e_r
  530.  
  531.        _7_-_1_.  _D_e_s_c_r_i_p_t_i_o_n 
  532.  
  533.           The CRobots   compiler   accepts   a  limited  subset  of  the  C
  534.        language.   There  is  no  provision for separate compilation, i.e.,
  535.        all  modules  of  a  program must be in one file. No preprocessor is
  536.        provided   for   "#define",   "#include",   etc.   Identifiers   are
  537.        significant  to  7  characters, although any length may be used. The
  538.  
  539.  
  540.                                   Page 8
  541.  
  542.  
  543. Tom Poindexter '85                                      David Wright '89-90
  544.  
  545.  
  546.        compiler  will  compile  any  file,  but  will  convert any existing
  547.        extension  to  (or  add  the  extension) ".cr". CRobots reserves the
  548.        extension  ".cr" for "Compiled Robot", and will not like other files
  549.        using  the  same  names. For consistency, use the extension ".r" for
  550.        robot  source  code  files,  and  let  the  compiler convert them to
  551.        ".cr".  
  552.  
  553.        _7_-_2_.  _F_e_a_t_u_r_e_s _m_i_s_s_i_n_g _f_r_o_m _s_t_a_n_d_a_r_d _C 
  554.  
  555.           Major language  features  missing  from  K&R are:  floating point
  556.        variables,   structures,  unions,  pointers,  initializers,  arrays,
  557.        character   data,  typedefs,  for  statement,  do..while  statement,
  558.        switch..case  statement,  break, continue, gotos and labels, ternary
  559.        and  comma operators, octal and hexadecimal constants, no parameters
  560.        to main(), no I/O functions, and all preprocessor directives.  
  561.  
  562.  
  563.        _7_-_3_.  _C_R_o_b_o_t_s _l_a_n_g_u_a_g_e 
  564.  
  565.           The language  features that are present are entirely suitable for
  566.        writing  robot  control  programs.  Basic  programming constructs of
  567.        if..then..else,  while, and function calls can be used freely.  Full
  568.        expression evaluation is also provided, so that statements such as: 
  569.  
  570.                if ((x = func1(y,1,++z,func2(c))) > 0) 
  571.                  a = 0; 
  572.                else 
  573.                  a = x; 
  574.  
  575.        are  perfectly legal. Ifs and whiles may be nested, and recursion is
  576.        supported.  Variables  declared  outside  a  function definition are
  577.        global  in  scope,  whereas  variables  declared  inside  a function
  578.        definition are local to that function.  
  579.  
  580.  
  581.        The following keywords are recognized: 
  582.  
  583.        ccoommmmeennttss::
  584.        "/* ... */"     comments cannot be nested
  585.  
  586.        ccoonnssttaannttss::
  587.        any decimal digits, optionally preceeded with a '-'
  588.  
  589.        ddeeccllaarraattiioonnss::
  590.        "int"           variable declare
  591.        "long"          same as int
  592.        "auto"          default storage scope, optional
  593.        "register"      legal, but ignored, same as auto
  594.        "function (parms,.....)"  function definition
  595.  
  596.  
  597.  
  598.  
  599.  
  600.                                   Page 9
  601.  
  602.  
  603. Tom Poindexter '85                                      David Wright '89-90
  604.  
  605.  
  606.        llooggiicc ccoonnttrrooll::
  607.        "if (expr) STMT else STMT"
  608.  
  609.        iitteerraattiioonn::
  610.        "while (expr) STMT"
  611.  
  612.        ffuunnccttiioonn rreettuurrnn::
  613.        "return"        return
  614.        "return expr"   return with a value
  615.  
  616.        aassssiiggnnmmeenntt ooppeerraattoorrss::
  617.        "="             assignment
  618.        ">>="           assignment shift right
  619.        "<<="           assignment shift left
  620.        "+="            assignment addition
  621.        "-="            assignment subtraction
  622.        "*="            assignment multiplication
  623.        "/="            assignment division
  624.        "%="            assignment modulo
  625.        "&="            assignment and
  626.        "^="            assignment exclusive or
  627.        "|="            assignment inclusive or
  628.  
  629.        bbiitt--wwiissee ooppeerraattoorrss::
  630.        ">>"            shift right
  631.        "<<"            shift left
  632.        "&"             and
  633.        "!"             unary not
  634.        "~"             unary one's complement
  635.        "^"             exclusive or
  636.        "|"             inclusive or
  637.  
  638.        iinnccrreemmeenntt//ddeeccrreemmeenntt ooppeerraattoorrss::
  639.        "++"            prefix or postfix increment
  640.        "--"            prefix or postfix decrement
  641.  
  642.        llooggiiccaall ooppeerraattoorrss::
  643.        "&&"            logical and
  644.        "||"            logical or
  645.        "<="            logical less than or equal
  646.        ">="            logical greater than or equal
  647.        "=="            logical equal
  648.        "!="            logical not equal
  649.        "<"             logical less than
  650.        ">"             logical greater than
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.                                   Page 10
  661.  
  662.  
  663. Tom Poindexter '85                                      David Wright '89-90
  664.  
  665.  
  666.        aarriitthhmmeettiicc ooppeerraattoorrss::
  667.        "-"             subtraction or unary negation
  668.        "+"             addition
  669.        "*"             multiplication
  670.        "/"             division
  671.        "%"             modulo
  672.  
  673.        mmiisscc::
  674.        ";"             statement terminator or null statement
  675.        "{ }"           compound statement
  676.        ","             parameter separator in function definition or call
  677.        "( )"           expression or function definition or call
  678.  
  679.        Precedence and order of evaluation are the same as in K&R.
  680.  
  681.                Operator                Associativity
  682.                ()                      left to right
  683.                ! ~ ++ -- -             right to left
  684.                * / %                   left to right
  685.                + -                      "   "    "
  686.                << >>                    "   "    "
  687.                < <= => >                "   "    "
  688.                == !=                    "   "    "
  689.                &                        "   "    "
  690.                ^                        "   "    "
  691.                |                        "   "    "
  692.                &&                       "   "    "
  693.                ||                       "   "    "
  694.                = -= += etc.            right to left
  695.  
  696.  
  697.        Major derivations from K&R:
  698.  
  699.       -Local variables  need  not  be  declared before reference, i.e., any
  700.        undeclared variable will default to a local variable.  
  701.  
  702.       -Intrinsic function names are reserved.  
  703.  
  704.  
  705.        _7_-_4_.  _C_o_m_p_i_l_e_r _l_i_m_i_t_s 
  706.  
  707.            defined functions:             64 
  708.            local variables per function:  64 
  709.            external variables:            64 
  710.            if nest level:                 16 
  711.            while nest level:              16 
  712.            line length                    2000 bytes 
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.                                   Page 11
  721.  
  722.  
  723. Tom Poindexter '85                                      David Wright '89-90
  724.  
  725.  
  726.        _7_-_5_.  _C_o_m_p_l_i_e_r _e_r_r_o_r _a_n_d _w_a_r_n_i_n_g _m_e_s_s_a_g_e_s_: 
  727.  
  728.           The compiler  has  no  error  recovery and will stop on the first
  729.        error found. Warning messages do not stop the compiler.  
  730.  
  731.        EErrrroorr mmeessssaaggeess 
  732.  
  733.        "syntax error"  -  Any  input that results in improper C syntax will
  734.             yield  "syntax  error",  with  an  indicator  pointing  to  the
  735.             unrecognizable input.  
  736.  
  737.        "instruction space  exceeded" - compiler tried to generate more than
  738.             1000 machine instructions.  
  739.  
  740.        "symbol pool  exceeded"  -  the  maximum  local  variable,  external
  741.             variable, or function definition symbol table was exceeded.  
  742.  
  743.        "function referenced  but  not  found"  -  a function was referenced
  744.             that  was  not defined in the input file or is not an intrinsic
  745.             function.  
  746.  
  747.        "main not  defined"  -  the  input  file  did  not define a 'main()'
  748.             function.  
  749.  
  750.        "function definition  same  as  intrinsic"  - a function was defined
  751.             with   the  same  name  as  an  intrinsic  function,  which  is
  752.             reserved.  
  753.  
  754.        "if nest level exceeded" - more than 16 'if's were nested.  
  755.  
  756.        "while nest level exceeded" - more than 16 'while's were nested.  
  757.  
  758.        "yacc stack  overflow"  - the compiler's parser overflowed, probably
  759.             due to complex expressions and/or extreme nesting.  
  760.  
  761.        WWaarrnniinngg mmeessssaaggeess 
  762.  
  763.           These messages  will  not  cause  the  compiler  to fail, but may
  764.        cause the program to execute unexpectedly.  
  765.  
  766.        "unsupported initializer"  -  variable  declares  cannot  include an
  767.             initializer. For future releases.  
  768.  
  769.        "unsupported break"  -  the 'break' statement was found and ignored.
  770.             For future releases.  
  771.  
  772.        "n undeclared  variables"  -  one  or more variables were implicitly
  773.             declared.  
  774.  
  775.        "code utilization:   n%"   -   reports   the   capacity  of  machine
  776.             instructions generated.  
  777.  
  778.  
  779.  
  780.                                   Page 12
  781.  
  782.  
  783. Tom Poindexter '85                                      David Wright '89-90
  784.  
  785.  
  786.        _7_-_6_. _C_o_m_p_i_l_e_r _N_o_t_e_s_: 
  787.  
  788.           The version  2.3  compiler  will generate the postfix increment /
  789.        decrement  operators,  but  you  should be aware of the size penalty
  790.        when  using  them.  Prefix  operators  only generate 3 instructions,
  791.        while postfix operations generate 5 instructions.  
  792.  
  793.                      _8_.  _C_R_o_b_o_t_s _C _I_n_t_r_i_n_s_i_c _F_u_n_c_t_i_o_n _L_i_b_r_a_r_y
  794.  
  795.           The intrinsic  function  library  provides  machine level control
  796.        and  certain  arithmetic  functions.  These functions do not consume
  797.        any  of  the  program code space or data stack, except for the three
  798.        words  for call/return sequences. No explicit linking is required to
  799.        use any intrinsic function.  
  800.  
  801.  
  802.        scan (degree,resolution) 
  803.  
  804.           The scan()  function  invokes the robot's scanner, at a specified
  805.        degree  and resolution. scan() returns 0 if no robots are within the
  806.        scan  range  or  a  positive  integer  representing the range to the
  807.        closest  robot.  Degree  should be within the range 0-359, otherwise
  808.        degree  is  forced  into  0-359  by a modulo 360 operation, and made
  809.        positive  if  necessary.  Resolution  controls the scanner's sensing
  810.        resolution, up to +/- 10 degrees.  Examples: 
  811.           range = scan(45,0); /* scan 45, with no variance */ 
  812.           range = scan(365,10); /* scans the range from 355 to 15 */ 
  813.  
  814.  
  815.        cannon (degree,range) 
  816.  
  817.           The cannon()  function  fires  the  PPC  at a specified range and
  818.        direction.  cannon()  returns 1 (true) if a pulse was discharged, or
  819.        0  (false) if the PPC is recharging. Degree is forced into the range
  820.        0-359  as  in  scan().  Range  can  be  0-700,  with  greater ranges
  821.        truncated to 700.  Examples: 
  822.           degree = 45;    /* set a direction to test */ 
  823.           if ((range=scan(degree,2)) > 0) /* see if a target is there */ 
  824.             cannon(degree,range);  /* fire a missile */ 
  825.  
  826.  
  827.        drive (degree,speed) 
  828.  
  829.           The drive()  function activates the robot's drive mechanism, on a
  830.        specified  heading  and speed. Degree is forced into the range 0-359
  831.        as  in scan(). Speed is expressed as a percent, with 100 as maximum.
  832.        A  speed  of  0  disengages  the  drive. Changes in direction can be
  833.        negotiated at speeds of less than 50 percent.  Examples: 
  834.           drive(0,100);  /* head due east, at maximum speed */ 
  835.           drive(90,0);   /* stop motion */ 
  836.  
  837.  
  838.  
  839.  
  840.                                   Page 13
  841.  
  842.  
  843. Tom Poindexter '85                                      David Wright '89-90
  844.  
  845.  
  846.        damage() 
  847.  
  848.           The damage()  function  returns  the  current  amount  of  damage
  849.        incurred.  damage()  takes  no arguments, and returns the percent of
  850.        damage,  0-99.  (100  percent  damage  means the robot is completely
  851.        disabled, thus no longer running!) Examples: 
  852.          d = damage();       /* save current state */ 
  853.          ; ; ;               /* other instructions */ 
  854.          if (d != damage())  /* compare current state to prior state */ 
  855.          { 
  856.            drive(90,100);    /* robot has been hit, start moving */ 
  857.            d = damage();     /* get current damage again */ 
  858.          } 
  859.  
  860.  
  861.        speed () 
  862.  
  863.           The speed()  function  returns  the  current  speed of the robot.
  864.        speed()  takes  no  arguments,  and  returns  the  percent of speed,
  865.        0-100.  Note  that  speed()  may  not always be the same as the last
  866.        drive(),   because   of   acceleration  and  deacceleration  delays.
  867.        Examples: 
  868.          drive(270,100);   /* start drive, due south */ 
  869.          ; ; ;             /* other instructions */ 
  870.          if (speed() == 0) /* check current speed */ 
  871.          { 
  872.            drive(90,20); /* ran into the south wall, or another robot*/ 
  873.          } 
  874.  
  875.  
  876.  
  877.        loc_x ()     loc_y () 
  878.  
  879.           The loc_x()   function   returns   the  robot's  current  x  axis
  880.        location.   loc_x()  takes  no  arguments,  and  returns 0-999.  The
  881.        loc_y()  function  is  similar to loc_x(), but returns the current y
  882.        axis position.  
  883.           Examples: 
  884.              drive (180,50);  /* start heading for west wall */ 
  885.              while (loc_x() > 20) 
  886.                ;              /* do nothing until we are close */ 
  887.              drive (180,0);   /* stop drive */ 
  888.  
  889.  
  890.        rand (limit) 
  891.  
  892.           The rand()  function returns a random number between 0 and limit,
  893.        up to 32767.  
  894.           Examples: 
  895.             degree = rand(360);     /* pick a random starting point */ 
  896.             range = scan(degree,0); /* and scan */ 
  897.  
  898.  
  899.  
  900.                                   Page 14
  901.  
  902.  
  903. Tom Poindexter '85                                      David Wright '89-90
  904.  
  905.  
  906.  
  907.        sqrt (number) 
  908.  
  909.           The sqrt()  returns  the  square root of a number. Number is made
  910.        positive, if necessary.  
  911.           Examples: 
  912.              x = x1 - x2;     /* compute the classical distance formula */ 
  913.              y = y1 - y2;     /* between two points (x1,y1) (x2,y2) */ 
  914.              distance = sqrt((x*x) - (y*y));  
  915.  
  916.  
  917.        sin (degree)    cos (degree)     tan (degree)     atan (ratio) 
  918.  
  919.           These functions  provide  trigonometric values. sin(), cos(), and
  920.        tan(),  take a degree argument, 0-359, and returns the trigonometric
  921.        value  times  100,000.  The scaling is necessary since the robot cpu
  922.        is  an  integer  only  machine,  and trig values are between 0.0 and
  923.        1.0.  atan()  takes  a  ratio  argument  that  has been scaled up by
  924.        100,000,  and  returns  a  degree  value,  between  -90 and +90. The
  925.        resulting  calculation  should  not  be  scaled  to the actual value
  926.        until   the   final   operation,  as  not  to  lose  accuracy.   See
  927.        programming examples for usage.  
  928.  
  929.  
  930.                          _9_.  _C_R_o_b_o_t_s _C _P_r_o_g_r_a_m _S_t_r_u_c_t_u_r_e
  931.  
  932.        _9_-_1_.  _B_a_s_i_c _p_r_o_g_r_a_m _s_t_r_u_c_t_u_r_e 
  933.  
  934.           CRobots programs  are  not  unlike  other C programs. The minimum
  935.        CRobots  program  consist  of a function named "main". Additionally,
  936.        other functions can be defined, along with external variables.  
  937.           There is  one  restriction  about robot source files. The first 2
  938.        lines  are  reserved  for  the "Company" which produces a robot, and
  939.        the  "Author"  of the robot, respectively. As an example, a club may
  940.        use  the  same "company" name, while putting the programmer for each
  941.        robot  in  the  "author"  spot.  This lets you share your robot with
  942.        other  players,  and still get credit for writing it. Both "company"
  943.        and  "author"  may  be  up to 15 characters long. If you do not want
  944.        these fields, you _M_U_S_T make the first 2 lines blank.  
  945.  
  946.           When a  .r  file  is  compiled,  a file with the extension of .cr
  947.        will  be  created.  This  is  the  robot in a compiled and encrypted
  948.        format.  You  can  give  this file out for competition (as mentioned
  949.        above)  without  giving out your source code. Additionally, each .cr
  950.        file  keeps  track  of  wins  and  losses  since  the robot was last
  951.        compiled   (needless   to   say,  but  to  prevent  major  lawsuits,
  952.        recompiling a robot will clear out the stats).  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.                                   Page 15
  961.  
  962.  
  963. Tom Poindexter '85                                      David Wright '89-90
  964.  
  965.  
  966.        _9_-_2 _"_s_n_i_p_e_r_._r_" 
  967.  
  968.           The following CRobots program is provided as an example.  
  969.  
  970.     CRobots, Inc.
  971.     T. Poindexter
  972.     /* sniper */
  973.     /* strategy: since a scan of the entire battlefield can be done in 90 */
  974.     /* degrees from a corner, sniper can scan the field quickly. */
  975.  
  976.     /* external variables, that can be used by any function */
  977.     int corner;           /* current corner 0, 1, 2, or 2 */
  978.     int c1x, c1y;         /* corner 1 x and y */
  979.     int c2x, c2y;         /*   "    2 "  "  " */
  980.     int c3x, c3y;         /*   "    3 "  "  " */
  981.     int c4x, c4y;         /*   "    4 "  "  " */
  982.     int s1, s2, s3, s4;   /* starting scan position for corner 1 - 4 */
  983.     int sc;               /* current scan start */
  984.     int d;                /* last damage check */
  985.  
  986.     /* main */
  987.     main()
  988.     {
  989.       int closest;        /* check for targets in range */
  990.       int range;          /* range to target */
  991.       int dir;            /* scan direction */
  992.  
  993.       /* initialize the corner info */
  994.       /* x and y location of a corner, and starting scan degree */
  995.       c1x = 10;  c1y = 10;  s1 = 0;
  996.       c2x = 10;  c2y = 990; s2 = 270;
  997.       c3x = 990; c3y = 990; s3 = 180;
  998.       c4x = 990; c4y = 10;  s4 = 90;
  999.       closest = 9999;
  1000.       new_corner();       /* start at a random corner */
  1001.       d = damage();       /* get current damage */
  1002.       dir = sc;           /* starting scan direction */
  1003.  
  1004.       while (1) {         /* loop is executed forever */
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.                                   Page 16
  1021.  
  1022.  
  1023. Tom Poindexter '85                                      David Wright '89-90
  1024.  
  1025.  
  1026.         while (dir < sc + 90) {  /* scan through 90 degree range */
  1027.           range = scan(dir,1);   /* look at a direction */
  1028.           if (range <= 700 && range > 0) {
  1029.             while (range > 0) {    /* keep firing while in range */
  1030.               closest = range;     /* set closest flag */
  1031.               cannon(dir,range);   /* fire! */
  1032.               range = scan(dir,1); /* check target again */
  1033.               if (d + 15 > damage())  /* sustained several hits, */
  1034.                 range = 0;            /* goto new corner */
  1035.             }
  1036.           dir -= 10;             /* back up scan, in case */
  1037.           }
  1038.  
  1039.           dir += 2;                /* increment scan */
  1040.           if (d != damage()) {     /* check for damage incurred */
  1041.             new_corner();          /* we're hit, move now */
  1042.             d = damage();
  1043.             dir = sc;
  1044.           }
  1045.         }
  1046.  
  1047.         if (closest == 9999) {       /* check for any targets in range */
  1048.           new_corner();             /* nothing, move to new corner */
  1049.           d = damage();
  1050.           dir = sc;
  1051.         } else                      /* targets in range, resume */
  1052.           dir = sc;
  1053.         closest = 9999;
  1054.       }
  1055.  
  1056.     }  /* end of main */
  1057.  
  1058.     /* new corner function to move to a different corner */
  1059.     new_corner() {
  1060.       int x, y;
  1061.       int angle;
  1062.       int new;
  1063.  
  1064.  
  1065.  
  1066.  
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.                                   Page 17
  1081.  
  1082.  
  1083. Tom Poindexter '85                                      David Wright '89-90
  1084.  
  1085.  
  1086.       new = rand(4);           /* pick a random corner */
  1087.       if (new == corner)       /* but make it different than the */
  1088.         corner = (new + 1) % 4;/* current corner */
  1089.       else
  1090.         corner = new;
  1091.       if (corner == 0) {       /* set new x,y and scan start */
  1092.         x = c1x;
  1093.         y = c1y;
  1094.         sc = s1;
  1095.       }
  1096.       if (corner == 1) {
  1097.         x = c2x;
  1098.         y = c2y;
  1099.         sc = s2;
  1100.       }
  1101.       if (corner == 2) {
  1102.         x = c3x;
  1103.         y = c3y;
  1104.         sc = s3;
  1105.       }
  1106.       if (corner == 3) {
  1107.         x = c4x;
  1108.         y = c4y;
  1109.         sc = s4;
  1110.       }
  1111.  
  1112.       /* find the heading we need to get to the desired corner */
  1113.       angle = plot_course(x,y);
  1114.  
  1115.       /* start drive train, full speed */
  1116.       drive(angle,100);
  1117.  
  1118.       /* keep traveling until we are within 100 meters */
  1119.       /* speed is checked in case we run into wall, other robot */
  1120.       /* not terribly great, since were are doing nothing while moving */
  1121.  
  1122.       while (distance(loc_x(),loc_y(),x,y) > 100 && speed() > 0)
  1123.         ;
  1124.  
  1125.       /* cut speed, and creep the rest of the way */
  1126.  
  1127.       drive(angle,20);
  1128.       while (distance(loc_x(),loc_y(),x,y) > 10 && speed() > 0)
  1129.         ;
  1130.  
  1131.       /* stop drive, should coast in the rest of the way */
  1132.       drive(angle,0);
  1133.     }  /* end of new_corner */
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.                                   Page 18
  1141.  
  1142.  
  1143. Tom Poindexter '85                                      David Wright '89-90
  1144.  
  1145.  
  1146.     /* classical pythagorean distance formula */
  1147.     distance(x1,y1,x2,y2)
  1148.     int x1;
  1149.     int y1;
  1150.     int x2;
  1151.     int y2;
  1152.     {
  1153.       int x, y;
  1154.  
  1155.       x = x1 - x2;
  1156.       y = y1 - y2;
  1157.       d = sqrt((x*x) + (y*y));
  1158.       return(d);
  1159.     }
  1160.  
  1161.     /* plot course function, return degree heading to */
  1162.     /* reach destination x, y; uses atan() trig function */
  1163.     plot_course(xx,yy)
  1164.     int xx, yy;
  1165.     {
  1166.       int d;
  1167.       int x,y;
  1168.       int scale;
  1169.       int curx, cury;
  1170.  
  1171.       scale = 100000;  /* scale for trig functions */
  1172.       curx = loc_x();  /* get current location */
  1173.       cury = loc_y();
  1174.       x = curx - xx;
  1175.       y = cury - yy;
  1176.  
  1177.       /* atan only returns -90 to +90, so figure out how to use */
  1178.       /* the atan() value */
  1179.  
  1180.       if (x == 0) {      /* x is zero, we either move due north or south */
  1181.         if (yy > cury)
  1182.           d = 90;        /* north */
  1183.         else
  1184.           d = 270;       /* south */
  1185.       } else {
  1186.         if (yy < cury) {
  1187.           if (xx > curx)
  1188.             d = 360 + atan((scale * y) / x);  /* south-east, quadrant 4 */
  1189.           else
  1190.             d = 180 + atan((scale * y) / x);  /* south-west, quadrant 3 */
  1191.         } else {
  1192.           if (xx > curx)
  1193.             d = atan((scale * y) / x);        /* north-east, quadrant 1 */
  1194.           else
  1195.             d = 180 + atan((scale * y) / x);  /* north-west, quadrant 2 */
  1196.         }
  1197.       }
  1198.  
  1199.  
  1200.                                   Page 19
  1201.  
  1202.  
  1203. Tom Poindexter '85                                      David Wright '89-90
  1204.  
  1205.  
  1206.       return (d);
  1207.     }
  1208.  
  1209.  
  1210.           Notes:  The  distance()  and  plot_course()  routines  are  quite
  1211.        handy.  Save  them  for your programs. Also, note that the main scan
  1212.        routine  will  "back up" a few degrees after a target has been found
  1213.        and  fired  upon.  This should catch robots trying to flee away from
  1214.        the  direction  you are scanning. If the target moves the other way,
  1215.        the normal scan increment will find it.  
  1216.  
  1217.           See the other sample CRobots program files.  
  1218.  
  1219.  
  1220.                      _1_0_.  _C_R_o_b_o_t_s _C_P_U _A_r_c_h_i_t_e_c_t_u_r_e _a_n_d _T_h_e_o_r_y
  1221.  
  1222.           This information  is  provided  if  you  need  to  use  the debug
  1223.        facility,  or  are  curious  about  the virtual machine interpreter.
  1224.        Don't  bother reading this section if you are not so inclined; it is
  1225.        not needed for normal play.  
  1226.  
  1227.        _1_0_-_1_.  _S_t_a_c_k _u_s_a_g_e_: 
  1228.  
  1229.           The stack  is  controlled  implicitly  by several pointers. Stack
  1230.        pointers  are  not  accessible  through  machine  instructions. Most
  1231.        instructions  will  either push data onto the stack, or pop data off
  1232.        the  stack.  The  stack  is used from the bottom up (low memory) for
  1233.        data  and  temporary  storage,  and  is used from the top down (high
  1234.        memory)  for  saving  stack  pointers  and  the  program  counter on
  1235.        function call/return.  
  1236.  
  1237.           External (global)  variables  are allocated at the very bottom of
  1238.        the  stack,  and the local mark pointer for 'main' starts just after
  1239.        the  externals.  External variables are addressed from the beginning
  1240.        of the stack, by offset.  
  1241.  
  1242.           When a  function  is called (including 'main'), the stack pointer
  1243.        is  marked  (local  mark)  and  is  increased by the number of local
  1244.        variables  needed  for  that function. Local variables are addressed
  1245.        relative  to  the local mark, by offsets. All calculations, function
  1246.        calls,  and  constants  are  pushed  on  and popped off the stack as
  1247.        needed (temporary mark or top of stack).  
  1248.  
  1249.           A function  call  also  saves  its  current stack pointers (local
  1250.        variable  mark  and  frame  mark)  and  program counter. This return
  1251.        information grows from the top down.  
  1252.  
  1253.           Arguments are  passed  to  functions by value. The first argument
  1254.        in  a  function call becomes the first local variable for the called
  1255.        function. Consider the following: 
  1256.  
  1257.           main()                 /* main has three local variables: */ 
  1258.  
  1259.  
  1260.                                   Page 20
  1261.  
  1262.  
  1263. Tom Poindexter '85                                      David Wright '89-90
  1264.  
  1265.  
  1266.           { 
  1267.             int a, b, c; 
  1268.             ....; 
  1269.             sub1 (a,b/2,c+1);    /* call sub1, and pass arguments */ 
  1270.             ....; 
  1271.           } 
  1272.  
  1273.           sub1 (x,y,z)           /* sub1 takes three parameters and */ 
  1274.           int x, y, z;           /* has one local variable */ 
  1275.           { 
  1276.             int result; 
  1277.             result = x + y + z; 
  1278.             return (result); 
  1279.           } 
  1280.  
  1281.           The main()  function  allocates  three  local  variables  on  the
  1282.        stack,  sets  its  local  mark  at 'a', and sets the temporary stack
  1283.        pointer  beyond  the locals. Just before sub1() is called, the value
  1284.        of  'a'  is pushed, followed by the result of 'b/2', and 'c+1'. When
  1285.        sub1()  is called, it sets its local mark where the value of 'a' is,
  1286.        so  that  'a' is known as 'x' in func1(), likewise 'b/2' is known as
  1287.        'y'  and  'c+1' is known as 'z'. Sub1() also allocates one more word
  1288.        for  'result',  and  sets  the  temporary mark after the storage for
  1289.        'result'.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.                                   Page 21
  1321.  
  1322.  
  1323. Tom Poindexter '85                                      David Wright '89-90
  1324.  
  1325.  
  1326.           The following diagram illustrates the stack usage: 
  1327.  
  1328.                +------------+   <-- end of stack, high memory 
  1329.                |main return |   <-- return info for main 
  1330.                +------------+       (frame,ip,local mark) 
  1331.                |sub1 return |   <-- return info for sub1 
  1332.                +------------+       (etc.) 
  1333.                |     |      | 
  1334.                |     v      |   <-- additional function call return 
  1335.                |            |       info grow downwards 
  1336.                |            | 
  1337.                |            | 
  1338.                |            | 
  1339.                |     ^      |   <-- additional function calls and 
  1340.                |     |      |       expressions grow upwards 
  1341.                |expressions | 
  1342.                +------------+   <-- temporary mark (top of stack) 
  1343.                |sub1 locals | 
  1344.                +------------+   <-- local mark: sub1 function 
  1345.                |main locals | 
  1346.                +------------+   <-- local mark: main function 
  1347.                |            | 
  1348.                | Externals  | 
  1349.                |            | 
  1350.                +------------+   <-- beginning of stack 
  1351.  
  1352.  
  1353.        _1_0_-_2_.  _L_i_n_k _l_i_s_t 
  1354.  
  1355.           The link  list  is a list built by the compiler that contains the
  1356.        names  and link information of the functions within the program. The
  1357.        link  information  contains  the  starting  location of the function
  1358.        within  the  code, the number of parameters, and the number of other
  1359.        local  variables  within  the  function.  The  link  list  cannot be
  1360.        accessed by the user program.  
  1361.  
  1362.        _1_0_-_3_.  _I_n_s_t_r_u_c_t_i_o_n _s_e_t 
  1363.  
  1364.           The CRobots  cpu  has  10 instructions. Each instruction occupies
  1365.        the same amount of storage, with or without operands.  
  1366.  
  1367.        FETCH offset  (external  |  local) - Fetch will retrieve a word from
  1368.             either  the  external  variable pool or the local variable pool
  1369.             and  push  it  onto  the stack. The offset has its high-bit set
  1370.             (or'ed  with  0x8000)  if  it  is  an external (offset from the
  1371.             beginning  of  the stack), otherwise it is a local (offset from
  1372.             the local variable mark). See STORE.  
  1373.  
  1374.        STORE offset  (external  |  local),  opcode - Store pops the top two
  1375.             items,  applies  the  arithmetic  opcode  to  the two operands,
  1376.             pushes  the result on the top of the stack and stores it in the
  1377.             variable  referenced by the offset. Offsets are either external
  1378.  
  1379.  
  1380.                                   Page 22
  1381.  
  1382.  
  1383. Tom Poindexter '85                                      David Wright '89-90
  1384.  
  1385.  
  1386.             or  local,  according  to  the  method  described in Fetch. The
  1387.             result  of  the  opcode  is  left  on  the stack. See FETCH and
  1388.             BINOP.  
  1389.  
  1390.        CONST k - Const will push a constant onto the stack.  
  1391.  
  1392.        BINOP opcode  -  Binop  will pop the top two items as top of stack =
  1393.             y,  next  to  top of stack as x, apply the arithmetic opcode as
  1394.             (x  opcode  y),  and  push the result on the stack. Opcodes are
  1395.             decimal  representations  of  'C'  operators  such as '+', '/',
  1396.             '>=', etc. See STORE.  
  1397.  
  1398.        FCALL link-offset  -  Fcall  performs  a  high  level  function call
  1399.             facility.  The  link-offset  operand  specifies an entry in the
  1400.             link  list  table.  Fcall  pushes  its return information:  the
  1401.             next  instruction  counter and the current local variable mark.
  1402.             A  new  local  variable  mark  and temporary mark (top of stack
  1403.             pointer)   is   set.   The  cpu  then  branches  to  the  first
  1404.             instruction of the function. See RETSUB and FRAME.  
  1405.  
  1406.        RETSUB -  Retsub  returns  from a function, leaving the return value
  1407.             on  the  top  of  the stack. Retsub restores the previous local
  1408.             variable  pool,  the  next  instruction counter, and re-adjusts
  1409.             the  stack  frame  to  the  point  just  before the call. The C
  1410.             compiler  generates  code  to  return  a  dummy  value  if  the
  1411.             function does not explicitly return one. See FCALL and FRAME.  
  1412.  
  1413.        BRANCH instruction  -  Branch pops the top of the stack and branches
  1414.             to  the  instruction  if the value is zero. The next sequential
  1415.             instruction  is  executed  if  the value is anything other than
  1416.             zero.  
  1417.  
  1418.        CHOP -  Chop  discards  the  top  of  the  stack  by popping it into
  1419.             oblivion.  
  1420.  
  1421.        FRAME -  Frame facilitates fcall/retsub by saving the current top of
  1422.             stack  pointer  (temporary  mark)  in  anticipation  of a fcall
  1423.             statement.   The   top   of  stack  pointer  is  saved  in  the
  1424.             call/return stack as a frame marker. See FCALL and RETSUB.  
  1425.  
  1426.        NOP - No operation. Is used as a mark indicating the end of code.  
  1427.  
  1428.        _1_0_-_4_. _M_a_c_h_i_n_e _l_e_v_e_l _d_e_b_u_g_g_i_n_g 
  1429.  
  1430.           Debug mode   is   used   to  trace  by  single  stepping  machine
  1431.        instructions.  Use  this  only  if  you  need  to  see  your program
  1432.        execute, or are just curious.  
  1433.  
  1434.           First, get  a listing on paper of a compile with full information
  1435.        by using the 'COMPILE TO' option: 
  1436.                A>crobots COMPILE TO prt: yourpgm.r 
  1437.  
  1438.  
  1439.  
  1440.                                   Page 23
  1441.  
  1442.  
  1443. Tom Poindexter '85                                      David Wright '89-90
  1444.  
  1445.  
  1446.           Next, start CRobots again with the 'DEBUG' flag: 
  1447.                A>crobots DEBUG yourpgm.r 
  1448.  
  1449.           Your robot  will  be  placed  randomly in the field, and a target
  1450.        robot  will  be  placed  at the center of the field (x=500,y=500) so
  1451.        your robot program can find and shoot at a target.  
  1452.  
  1453.           The virtual  machine  interpreter  will  single step through your
  1454.        program  (machine  instructions,  that  is). At every instruction, a
  1455.        machine  instruction  is  disassembled, and the top of stack pointer
  1456.        and  value  are  printed.  The  top of stack and value are after the
  1457.        results  of  the instruction. Other information may also be printed,
  1458.        such as function calls searching the link list, etc.  
  1459.  
  1460.           On every  step, you are prompted "d,h,q,<cr>:". Entering 'd' will
  1461.        dump   external   and   local  variable  pools,  as  well  as  vital
  1462.        information  of  your  robot:   coordinates, heading, speed, damage,
  1463.        etc.,  and  the  status  of  any missiles your robot may have fired.
  1464.        Entering  'h'  will  simulate your robot taking a 10% damage hit, so
  1465.        you  can  check  damage  detection,  etc. Entering 'q' will quit the
  1466.        program  immediately,  and return you to AmigaDOS. A carriage return
  1467.        alone  will  continue  the stepping process. All responses ('d','h',
  1468.        or  'q')  should  be  in  lower  case  only. You should refer to the
  1469.        compile  listing  for  offsets  into the external and local variable
  1470.        pools, C code, etc.  
  1471.  
  1472.                             _1_1_.  _I_m_p_l_e_m_e_n_t_a_t_i_o_n _n_o_t_e_s
  1473.  
  1474.           CRobots is  written  entirely  in  'C'.  The compiler section was
  1475.        developed  with the aid of the Unix* (TM) programs 'yacc' and 'lex'.
  1476.        Yacc  (yet  another  compiler-compiler)  accepts  a 'grammar', which
  1477.        describes  the  CRobots  'C'  language. Yacc produces a 'C' function
  1478.        known  as  a  parser.  The  parser  is  the  heart  of the compiler,
  1479.        recognizing  valid  'C' constructs. Lex (lexical analyzer) accepts a
  1480.        list  of token combinations, and produces a 'C' function to scan the
  1481.        compiler   input   for   the  tokens.  The  yacc  generated  parser,
  1482.        yyparse(),  repeatedly calls the lex generated analyzer, yylex(), to
  1483.        process  the  source  program.  The  initial screen display routines
  1484.        were developed with the 'curses' screen library.  
  1485.  
  1486.           The 'C'  source  code  was  then  ported  to  MS-DOS**  (TM), and
  1487.        recompiled  using  the  Lattice***  (TM)  2.15E  compiler, using the
  1488.        'small'  memory model. The screen display functions were modified to
  1489.        use   'int86()',  accessing  the  rom  INT  10H  cursor  positioning
  1490.        functions in the IBM-PC bios.  
  1491.  
  1492.           After it  was  ported  to  MS-DOS it was effectively abandoned by
  1493.        Tom  Poindexter,  and  at this time all attempts to contact him have
  1494.        failed.   I (David Wright) got a copy of it which had been ported to
  1495.        the  Amiga  almost  2  years  ago,  and  have been tracking down the
  1496.        source  code  ever since. In September of 1989 I was finally able to
  1497.        get  the  source  (for  the  IBM/Unix version) and re-port it to the
  1498.  
  1499.  
  1500.                                   Page 24
  1501.  
  1502.  
  1503. Tom Poindexter '85                                      David Wright '89-90
  1504.  
  1505.  
  1506.        Amiga.  At  my  first release it was still text based, but supported
  1507.        the ARP command line handler, stack handler, and file requesters.  
  1508.  
  1509.           My next  release included robots, explosions, and pulses as BOBs,
  1510.        and  2  custom  graphics  screens.  I  also  added   the  ability to
  1511.        pre-compile  the  robots,  so that they may be given out without the
  1512.        source  code  for  competition,  and so that a win/loss ratio can be
  1513.        encoded  into  the  file.  I  also want to create a standalone robot
  1514.        factory and test bench.  
  1515.  
  1516.           Tom was  asking  for  money  to get the source code, but I am not
  1517.        going  to  be  that  strict.  If  you want the latest version of the
  1518.        source,  send  me  a  self-addressed, stamped envelope with a single
  1519.        floppy  also included.  I will copy that latest, released, version I
  1520.        have onto it, and throw in my latest version of CoreWar to boot.  
  1521.  
  1522.         * Unix is a trademark of Bell Telephone Laboratories.  
  1523.         ** MS-DOS is a trademark of Microsoft, Inc.  
  1524.         *** Lattice is a trademark of Lattice, Inc.  
  1525.         **** IBM is a trademark of International Business Machines, Inc.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.                                   Page 25
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.                                 Table of Contents
  1567.  
  1568.           1. Distribution Agreement..................................    1
  1569.           2. Introduction............................................    1
  1570.              2-1. Description........................................    1
  1571.              2-2. Intended Audience..................................    1
  1572.              2-3. Machine requirements...............................    1
  1573.              2-4. User Interface.....................................    2
  1574.           3. Types of Play...........................................    2
  1575.           4. Running CRobots.........................................    2
  1576.              4-1. Command Line Options...............................    2
  1577.              4-2. Examples...........................................    3
  1578.              4-3. Running CRobots from the WorkBench.................    4
  1579.              4-4. Workbench examples.................................    4
  1580.           5. Game Parameters.........................................    4
  1581.              5-1. Battlefield........................................    4
  1582.              5-2. Robot Offense......................................    5
  1583.              5-3. Robot Defense......................................    5
  1584.              5-4. Disabling Opponents................................    6
  1585.              5-5. Sample Display.....................................    7
  1586.              5-6. Table of Time Costs................................    7
  1587.           6. CRobots CPU.............................................    8
  1588.           7. CRobots C Compiler......................................    8
  1589.              7-1. Description........................................    8
  1590.              7-2. Features Missing From Standard C...................    9
  1591.              7-3. CRobots Language...................................    9
  1592.              7-4. Compiler Limits....................................   11
  1593.              7-5. Compiler Error & Warning Messages..................   11
  1594.              7-6. Compiler Notes:....................................   12
  1595.           8. CRobots Intrinsic Function Library......................   13
  1596.           9. CRobots C Program Structure.............................   15
  1597.              9-1. Basic Program Structure............................   15
  1598.              9-2. "sniper.r".........................................   15
  1599.           10. CRobots CPU Architecture and Theory....................   20
  1600.              10-1. Stack usage.......................................   20
  1601.              10-2. Link list.........................................   22
  1602.              10-3. Instruction set...................................   22
  1603.              10-4. Machine level debugging...........................   23
  1604.           11. Implementation notes...................................   24
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.                                        - I -
  1621.  
  1622.